package com.kehongborui.net.socket.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * udp 客户端
 */
public class UdpServer {
    public static void main(String[] args) throws IOException {
        DatagramSocket client = new DatagramSocket(9998);  // 实例化 udp 客户端
        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer, 1024);  // 实例化数据包 对象
        System.out.println("等待客户端的数据");
        client.receive(packet); // 接收数据
        System.out.println(new String(packet.getData(), 0, packet.getLength()));
        client.close();
    }
}
